export const onCreateBabelConfig = ({ actions, store }, pluginOptions) => {
  if (store.getState().config.jsxRuntime === `automatic`) {
    actions.setBabelPlugin({
      name: require.resolve(`@emotion/babel-plugin`),
      options: {
        sourceMap: process.env.NODE_ENV !== `production`,
        autoLabel: `dev-only`,
        ...(pluginOptions ? pluginOptions : {}),
      },
    })
  } else {
    actions.setBabelPreset({
      name: require.resolve(`@emotion/babel-preset-css-prop`),
      options: {
        sourceMap: process.env.NODE_ENV !== `production`,
        autoLabel: `dev-only`,
        ...(pluginOptions ? pluginOptions : {}),
      },
    })
  }
}

exports.pluginOptionsSchema = ({ Joi }) =>
  Joi.object({
    sourceMap: Joi.boolean()
      .default(true)
      .description(
        `This option tells the plugin to inject source maps for use in browser dev tools in development.`
      ),
    autoLabel: Joi.string()
      .default(`dev-only`)
      .description(
        `This option automatically adds the label property to styles so that class names generated by css or styled include the name of the variable the result is assigned to. You can read more about this option in @emotion/babel-plugin's docs: https://emotion.sh/docs/@emotion/babel-plugin#autolabel`
      ),
    labelFormat: Joi.string()
      .default(`[local]`)
      .description(
        `This option only works when autoLabel is set to true. It allows you to define the format of the resulting label. The format is defined via string where variable parts are enclosed in square brackets []. For example labelFormat: "my-classname--[local]", where [local] will be replaced with the name of the variable the result is assigned to.`
      ),
    cssPropOptimization: Joi.boolean()
      .default(true)
      .description(
        `This option assumes that you are using something to make @emotion/react’s jsx function work for all jsx. If you are not doing so and you do not want such optimizations to occur, disable this option.`
      ),
  })
